# -*- coding:utf-8 -*-

import datetime
import time

from conf import baseInfo_url,baseInfo_run_interval
from getlib.get_basemessge import GetHardwareMessage
from send_data_api import cmdb_http_api


# from get_tomcatmessage import GetTomcatMessage
# from conf import tomcatInfo_error_log, tomcatInfo_run_interval, tomcatInfo_url

def baseInfo():
    flag = True
    info_message  = {'cpu':'','memory':'','network':'','platform':'','partition':'','main':''}
    # check the message between  info_message and new_message for sendData
    while True:
        sendData = {}
        new_message = GetHardwareMessage().run_all_get()
        if flag:
            for k,v in info_message.items():
                if v != info_message[k]:
                    info_message[k] = v
                    sendData[k] = v
        else:
            sendData = new_message

        # add time and main_ip
        reportTime = str(datetime.datetime.now())
        #sendData['reportTime'] = reportTime
        sendData['main_ip'] = new_message['main']['main_ip']
        # send message
        flag = cmdb_http_api(sendData,baseInfo_url)
        # wait time
        time.sleep(baseInfo_run_interval)

